#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.device.mqtt.produce;

import lombok.RequiredArgsConstructor;
import ${package}.base.mqtt.MqttMsgSendBaseService;
import ${package}.device.mqtt.event.DeviceNotifyMqttEvent;
import ${package}.device.mqtt.producer.DeviceMqttProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class DeviceMqttProducerImpl implements DeviceMqttProducer {
    @Autowired
    @Lazy
    private  MqttMsgSendBaseService<DeviceNotifyMqttEvent> mqttMsgSendBaseService;

    @Override
    public void deviceNotify(String topic, DeviceNotifyMqttEvent deviceNotifyMqttEvent) {
        Message<DeviceNotifyMqttEvent> message = MessageBuilder
                .withPayload(deviceNotifyMqttEvent)
                .setHeader(MqttHeaders.TOPIC, topic)
                .setHeader(MqttHeaders.QOS, 1)
                .setHeader("clazz", DeviceNotifyMqttEvent.class)
                .build();
        mqttMsgSendBaseService.send(message);
    }
}
